package config

import (
	"common/helper"
	"database/sql"
)

//渠道打码配置

/*
打码配置
*/

type CfgChannelWagedItem struct {
	ChannelId int     `json:"channel_id" db:"channel_id" cbor:"channel_id"`
	Type      int     `json:"ty" db:"ty" cbor:"ty"`
	FlowMul   float64 `json:"flow_multiple" db:"flow_multiple" cbor:"flow_multiple"`
}

var cfgChannelWagedList []CfgChannelWagedItem

func ChannelWagedCfgSetRow(rows *sql.Rows) {
	var tVal CfgChannelWagedItem
	var err error
	err = rows.Scan(&tVal.ChannelId, &tVal.Type, &tVal.FlowMul)
	if err != nil {
		helper.InfoLog("FlowCfgSetRow,scan err")
		return
	}

	cfgChannelWagedList = append(cfgChannelWagedList, tVal)
}

func ChannelWagedCfgRemove() {
	cfgChannelWagedList = []CfgChannelWagedItem{}
}

func GetChannelWagedMul(channelId int, ty int) float64 {
	nLen := len(cfgChannelWagedList)
	for index := 0; index < nLen; index++ {
		if cfgChannelWagedList[index].Type == ty &&
			cfgChannelWagedList[index].ChannelId == channelId {
			return cfgChannelWagedList[index].FlowMul
		}
	}

	return -1
}
